﻿define('system', function () {
    var isDebugging = false, system;

    var noop = function () { };

    var log = function () {
        try {
            // Modern browsers
            if (typeof console != 'undefined' && typeof console.log == 'function') {
                // Opera 11
                if (window.opera) {
                    var i = 0;
                    while (i < arguments.length) {
                        console.log('Item ' + (i + 1) + ': ' + arguments[i]);
                        i++;
                    }
                }
                    // All other modern browsers
                else if ((Array.prototype.slice.call(arguments)).length == 1 && typeof Array.prototype.slice.call(arguments)[0] == 'string') {
                    console.log((Array.prototype.slice.call(arguments)).toString());
                } else {
                    console.log(Array.prototype.slice.call(arguments));
                }
            }
        } catch (ignore) { }
    };

    system = {
        version: "1.0.0",
        noop: noop,
        debug: function (enable) {
            if (arguments.length == 1) {
                isDebugging = enable;
                if (isDebugging) {
                    this.log = log;
                    this.log('Debug mode enabled.');
                } else {
                    this.log('Debug mode disabled.');
                    this.log = noop;
                }
            } else {
                return isDebugging;
            }
        },
        isArray: function (obj) {
            return toString.call(obj) === '[object Array]';
        },
        log: noop,
        defer: function (action) {
            return $.Deferred(action);
        },
        guid: function () {
            return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
                var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
                return v.toString(16);
            });
        },
        keys: function (object) {
            var keys = [];
            for (var key in object) {
                if (object.hasOwnProperty(object, key)) {
                    keys.push(key);
                }
            }
            return keys;
        }
    };

    return system;

});